<?php

// +---------------------------------------------+
// |     Copyright  2010 - 2018 InterPhoto       |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+


// ######################################################

error_reporting(E_ALL & ~E_NOTICE);

@include('./config/InterPhoto.config.php');

if(!defined('INTERPHOTO'))
{
	header('Location: install/index.php');
	exit();
}

include(BASEPATH . 'includes/Class.Database.php');
include(BASEPATH . 'includes/InterPhoto.BaseUrl.php');

$DB = new DB;

$DB->database = $dbname;
$DB->server   = $servername;
$DB->user     = $dbusername;
$DB->password = $dbpassword;

$DB->connect();

$dbpassword   = '';
$DB->password = '';

$mainsettings = array();

$getmainsettings = $DB->query("SELECT varname, value FROM " . TABLE_PREFIX . "mainsettings");
while($setting = $DB->getrow($getmainsettings)) {
	$mainsettings[$setting['varname']] = $setting['value'];
}

define('APP_NAME', base64_decode($mainsettings['siteAppName']));
define('APP_VERSION', $mainsettings['siteAppVersion']);

define('T_PATH', BASEPATH.'templates/'.$mainsettings['siteDefaultTemplate'].'/');
define('T_URL', 'templates/'.$mainsettings['siteDefaultTemplate'].'/');
$mainsettings['siteTitle'] = $mainsettings['siteTitle'] . base64_decode('IC0gUG93ZXJlZCBieSA=') . APP_NAME . '!';

if(isset($_COOKIE['IPLANG'.COOKIE_KEY])){
	define('SITE_LANG', $_COOKIE['IPLANG'.COOKIE_KEY]);
}else{
	if($mainsettings['siteDefaultLang'] == 'Auto'){
		if (strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-cn') OR strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-tw'))
		{
			define('SITE_LANG', 'Chinese');
		}else{
			define('SITE_LANG', 'English');
		}
	}else{
		define('SITE_LANG', $mainsettings['siteDefaultLang']);
	}
}

include(BASEPATH.'languages/'.SITE_LANG.'.php');

include(BASEPATH.'includes/InterPhoto.Functions.php');
include(BASEPATH.'includes/InterPhoto.Auth.php');
include(BASEPATH.'includes/Class.Smarty.php');

if(!$mainsettings['siteActived']){
	$smarty = new InterPhoto;

	$smarty->assign('errortitle', $sys_langs['websiteoffline']);
	$smarty->assign('errors', Html($mainsettings['siteOffTitle']));
 
	$smarty->interPlay('error.tpl');
	exit();
}

if(!$mainsettings['siteAllowGuest'] AND !$userinfo['userid'] AND !$islogined AND !strstr($_SERVER['SCRIPT_NAME'], 'getbackpass') AND !strstr($_SERVER['SCRIPT_NAME'], 'register') AND !strstr($_SERVER['SCRIPT_NAME'], 'InterPhoto.vvc')){
	$smarty = new InterPhoto;
	$pagenav = '<a href="'.GetUrl('index.php').'">'.$langs['home'].'</a> '.$langs['nav'].' <a href="'.GetUrl('login.php').'">'.$langs['signup'].'</a>';

	$smarty->assign('loginforview', $sys_langs['loginforview']);
	$smarty->assign('pagenav', $pagenav);
	$smarty->assign('userinfo', $userinfo);
	$smarty->assign('pagetitle', $langs['signup']. ' - ' .$mainsettings['siteTitle']);

	$smarty->interPlay('login.tpl');
	exit();
}

?>